<template>
  <div class="header">
    <div class="header-left">
        <div class="text-gradient">新闻发布系统</div>
    </div>
       <div class="header-right">
           <img :src="userinfo.avatarUrl"  alt=" "  />
         <el-dropdown @command="handleClick">
       <span class="el-dropdown-link" style="font-size: 22px">
    {{ userinfo.username }}<i class="el-icon-arrow-down el-icon--right"></i>
  </span>
           <el-dropdown-menu slot="dropdown">
             <el-dropdown-item><el-link href="/home" target="_blank">回到前台</el-link></el-dropdown-item>
<!--             用户个人信息-->
             <el-dropdown-item command='personal'>个人信息</el-dropdown-item>
<!--             管理员个人信息-->
<!--             <el-dropdown-item command='personal'>个人信息</el-dropdown-item>-->
             <el-dropdown-item command='cancel'>退出</el-dropdown-item>
           </el-dropdown-menu>
         </el-dropdown>
        </div>
  </div>
</template>

<script>
import  pubsub from 'pubsub-js'
export default {
   data(){
    return {
      userinfo: {},
    }
   },
  created() {
    this.getUserinfo();
  },
  mounted() {
    pubsub.subscribe("sendMsg",()=>{
      // console.log(e,msg);//sendMsg 这是A组件发布的消息！
      this.getUserinfo();
    })
  },
  methods:{
    getUserinfo() {
      this.userinfo=JSON.parse(localStorage.getItem("user"))

    },
    handleClick(command){
      if(command==='cancel'){
        this.$router.push('/home')
        localStorage.removeItem("user")
        this.$message.success("退出成功")
      }else if (command === 'personal') {
        this.$router.push('/personal')
      }


 }
   }
}
</script>

<style lang="scss" scoped>
 .header {
   height: 100%;
  display: flex;
  align-items: center;
  justify-content:space-between;
 }
 .header-left{
    display: flex;
    align-items: center;
 }
 .header-left:nth-child(1){
    margin-left: 40px;
   font-size: 25px;
   font-weight: bold;
 }
.header-right {
  height: 70px;
  display: flex;
  justify-content: center;
  align-items: center;
  user-select: none;
  margin-right: 20px;
}
.header-right img{
  width: 45px;
  height: 45px;
  border-radius: 50%;
  background-color: #fff;
  margin-right: 20px;
  object-fit: cover;
}
.text-gradient {
  cursor: pointer;
  font-family: "楷体";
  font-size: 30px;
  font-style: italic;
  color: rgb(116, 148, 255);

}


</style>

